import { Button, Space } from 'ant-design-vue'
import { examineResultTypeObj, tableColumns } from './data'

export function useColumns(updateFunction: Function, detailFunction: Function, examineFunction: Function) {
  const getColumns = (column, record) => {
    if (column.dataIndex === 'licenseNumber') {
      return <span>{record.licenseNumber}</span>
    } else if (column.dataIndex === 'examineResultType') {
      let examineResultStr = ''
      examineResultTypeObj.forEach(model => {
        if (model.value === record.examineResultType) {
          examineResultStr = model.label
        }
      })
      return <span>{examineResultStr}</span>
    } else if (column.dataIndex === 'saleNumber') {
      return <span>{record.saleNumber}</span>
    } else if (column.dataIndex === 'returnNumber') {
      return <span>{record.returnNumber}</span>
    } else if (column.dataIndex === 'manyNumber') {
      return <span>{record.manyNumber}</span>
    } else if (column.dataIndex === 'lackNumber') {
      return <span>{record.lackNumber}</span>
    } else if (column.dataIndex === 'createTime') {
      return <span>{record.createTime}</span>
    } else if (column.key === 'action') {
      return (
        <Space>
          <Button
            type='link'
            onClick={() => detailFunction(record.code)}
            v-auth={['warehouse:sale-return-order:detail']}
          >
            详情
          </Button>
          <Button type='link' onClick={() => updateFunction(record.code)} v-auth={['warehouse:sale-return-order:edit']}>
            编辑
          </Button>
          <Button
            type='link'
            onClick={() => examineFunction(record.code)}
            v-auth={['warehouse:sale-return-order:edit']}
          >
            校验
          </Button>
        </Space>
      )
    }
  }
  return {
    getColumns,
    tableColumns
  }
}
